<?php if ( ! defined('BASEPATH')) exit('This file does not run directly. Sorry.'); ?>
<?php
/**
 * Kalaisoo.
 *
 * A lightweight no-framework framework written in PHP.
 *
 * @package Kalaisoo
 * @subpackage HTML
 * @author $Author: info@sah-company.com $
 * @version $Id: html.php 127 2012-01-12 01:46:11Z info@sah-company.com $
 */

/**
 * returns a string with HTML abbr.
 *
 * @param string $text
 * @param string $title
 * @return string
 **/
function abbr($text, $title)
{
	return '<abbr title="'.$title.'">'.$text.'</abbr>';
}

/**
 * returns a string with an unordered list.
 *
 * @param array $items
 * @param array $options
 * @return string
 */
function ul(array $items, array $options = array())
{
	return html_list($items, 'ul', $options);
}

/**
 * returns a string with an ordered list.
 *
 * @param array $items
 * @param array $options
 * @return string
 */
function ol(array $items, array $options = array())
{
	return html_list($items, 'ol', $options);
}

/**
 * returns either a ordered or unordered HTML list.
 *
 * There is usually no need to call this directly as you would use ul()
 * for unordered lists or ol() for ordered lists.
 *
 * @param mixed $items
 * @param string $list_type
 * @param array $options
 * @return string
 */
function html_list($items, $type = 'ul', array $options = array())
{
	if ( ! is_array($items))
	{
		return $items;
	}
	$stack = glue($options);	
	$html = "<{$type}{$stack}>\n";
	static $last_key = '';
	foreach ($items as $key=>$value)
	{
		$last_key = $key;
		$html .= '<li>';
		if (is_array($value))
		{
			$html .= "{$last_key}\n";
			$html .= html_list($value, $type);
		}
		else
		{
			$html .= $value;
		}	
		$html .= "</li>\n";
	}
	$html .= "</{$type}>\n";
	return $html;
}
?>